package cc.codeshop.aidlserver;

import java.util.Locale;

import android.os.Parcel;
import android.os.Parcelable;

public class Person implements Parcelable {
	
	private int id;
	private String name;
	
	public Person() {}
	
	public Person(Parcel parcel) {
		readFromParcel(parcel);
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public String toString() {
		return String.format("id : %d, name : %s ",  id, name);
	}
	
	@Override
	public int describeContents() {
		return 0;
	}
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(id);
		dest.writeString(name);
	}
	
	/**
	 * AIDL生成的文件中有调用这个方法
	 * @param source
	 * @return
	 */
	public void readFromParcel(Parcel source) {
		this.id = source.readInt();
		this.name = source.readString();
	}
	
	/**
	 * AIDL生成的文件中有调用这个构造器
	 */
	public static final Parcelable.Creator<Person> CREATOR = new Parcelable.Creator<Person>() {

		@Override
		public Person createFromParcel(Parcel source) {
			return new Person(source);
		}

		@Override
		public Person[] newArray(int size) {
			return new Person[size];
		}
		
	};

}
